<?php
/**
 * 增值服务管理
 * author:ty
 * date:2018-2-2
*/
namespace App\Http\Controllers;

use App\Http\Models\Extra;
use Illuminate\Support\Facades\Input;

class ExtraController extends Controller
{
    //室内设计
    public function interior()
    {
        $request = array(
            'userid' => array('value'=>Input::get('userid'),'isnumber'=>true,'empty'=>true,'declare'=>'当前用户id'),
            'design_name' => array('value'=>Input::get('design_name'),'isnumber'=>false,'empty'=>true,'declare'=>'装修类别'),
            'design_type' => array('value'=>Input::get('design_type'),'isnumber'=>false,'empty'=>true,'declare'=>'风格类型'),
            'design_space' => array('value'=>Input::get('design_space'),'isnumber'=>false,'empty'=>true,'declare'=>'空间面积'),
            'design_amount' => array('value'=>Input::get('design_amount'),'isnumber'=>false,'empty'=>true,'declare'=>'预算报价'),
            'design_require' => array('value'=>Input::get('design_require'),'isnumber'=>false,'empty'=>false,'declare'=>'设计需求描述')
        );
        //参数校验
        $param= array();
        foreach ($request as $key=>$val) {
            if($val['empty']){
                if(empty($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'为必填参数'];
                    return response()->json($result);
                }
                if($val['isnumber'] && !is_numeric($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'数据类型不在规定范围内'];
                    return response()->json($result);
                }
            }
            $param[$key]=trim($val['value']);
        }
        $data = Extra::interior($param);

        $result = ['code'=>200,'messages'=>'室内设计接口数据反馈','result'=>$data];

        return response()->json($result);
    }

    //定制化产品
    public function customized()
    {
        $request = array(
            'userid' => array('value'=>Input::get('userid'),'isnumber'=>true,'empty'=>true,'declare'=>'当前用户id'),
            'customized_size' => array('value'=>Input::get('customized_size'),'isnumber'=>false,'empty'=>true,'declare'=>'产品尺寸'),
            'customized_color' => array('value'=>Input::get('customized_color'),'isnumber'=>false,'empty'=>true,'declare'=>'产品颜色'),
            'customized_num' => array('value'=>Input::get('customized_num'),'isnumber'=>false,'empty'=>true,'declare'=>'定制数量'),
            'customized_use' => array('value'=>Input::get('customized_use'),'isnumber'=>false,'empty'=>true,'declare'=>'用途'),
            'customized_require' => array('value'=>Input::get('customized_require'),'isnumber'=>false,'empty'=>false,'declare'=>'具体需求')
        );
        //参数校验
        $param= array();
        foreach ($request as $key=>$val) {
            if($val['empty']){
                if(empty($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'为必填参数'];
                    return response()->json($result);
                }
                if($val['isnumber'] && !is_numeric($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'数据类型不在规定范围内'];
                    return response()->json($result);
                }
            }
            $param[$key]=$val['value'];
        }
        $data = Extra::customized($param);

        $result = ['code'=>200,'messages'=>'定制化接口数据反馈','result'=>$data];

        return response()->json($result);
    }

    //搬家服务
    public function moverservice()
    {
        $request = array(
            'userid' => array('value'=>Input::get('userid'),'isnumber'=>true,'empty'=>true,'declare'=>'当前用户id'),
            'move_name' => array('value'=>Input::get('move_name'),'isnumber'=>false,'empty'=>true,'declare'=>'联系人姓名'),
            'move_phone' => array('value'=>Input::get('move_phone'),'isnumber'=>false,'empty'=>true,'declare'=>'联系电话'),
            'move_email' => array('value'=>Input::get('move_email'),'isnumber'=>false,'empty'=>true,'declare'=>'联系邮箱'),
            'move_addr' => array('value'=>Input::get('move_addr'),'isnumber'=>false,'empty'=>true,'declare'=>'搬家地址'),
            'move_require' => array('value'=>Input::get('move_require'),'isnumber'=>false,'empty'=>false,'declare'=>'搬家具体需求')
        );
        //参数校验
        $param= array();
        foreach ($request as $key=>$val) {
            if($val['empty']){
                if(empty($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'为必填参数'];
                    return response()->json($result);
                }
                if($val['isnumber'] && !is_numeric($val['value'])){
                    $result = ['code'=>'1004','messages'=>$key.$val['declare'].'数据类型不在规定范围内'];
                    return response()->json($result);
                }
            }
            $param[$key]=$val['value'];
        }
        $data = Extra::moverservice($param);

        $result = ['code'=>200,'messages'=>'搬家服务接口数据反馈','result'=>$data];

        return response()->json($result);
    }
}
